import { ResponseCode } from "@/enum/ResponseCode";
import { updateMyUser } from "@/servers/api/userController";
import {
  Button,
  Form,
  Grid,
  Input,
  Message,
  Typography,
} from "@arco-design/web-react";
import { useModel } from "umi";
const FormItem = Form.Item;
export default () => {
  const [form] = Form.useForm();
  const { loginUser } = useModel("@@initialState").initialState || {};
  const onSubmit = async () => {
    const data = form.getFieldsValue() as API.UserUpdateMyRequest;
    let res = await updateMyUser(data);
    if (res.data.code === ResponseCode.SUCCESS) {
      Message.success("修改成功");
    } else {
      Message.error(res.data.message as string);
    }
  };
  return (
    <div>
      <Typography.Title heading={5} style={{ margin: 0 }}>
        基本设置
      </Typography.Title>
      <Grid.Row align="start" justify="space-between">
        <Grid.Col md={8} sm={24} xs={24}>
          <Form
            form={form}
            layout="vertical"
            autoComplete="off"
            initialValues={loginUser}
          >
            <FormItem field="oldPassword" label="旧密码">
              <Input.Password placeholder="请输入" allowClear />
            </FormItem>
            <FormItem field="newPassword" label="新密码">
              <Input.Password placeholder="请输入" allowClear />
            </FormItem>
            <FormItem wrapperCol={{ offset: 0 }}>
              <Button type="primary" onClick={onSubmit}>
                保存
              </Button>
            </FormItem>
          </Form>
        </Grid.Col>
      </Grid.Row>
    </div>
  );
};
